package cn.cn.tedu.file;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.net.URL;
import java.util.Arrays;
import java.util.Scanner;


/**
 * @author ：Dsi
 * @date ：2021/11/16 15:53
 * Describe ：
 */
public class TestURL {
    public static void main(String[] args) throws Throwable {
        method2();
        //method4();
    }
    //处理method2的异常

    public static String[] method2()  throws Throwable{
        int a;
        String[] outJpg;
        // 获取用户输入网址
        //System.out.println("输入网址：");
        //String b = new Scanner(System.in).nextLine();
        String b = "https://pic.netbian.com/4kdongman/";
        //创建接受文件
        new File("D:\\SecondElement_SourceCode\\").mkdir();
        new File("D:\\SecondElement_SourceCode\\1.txt");
        new File("D:\\SecondElement\\").mkdir();
        new File("D:\\SecondElement\\1.txt");
        BufferedWriter out=new BufferedWriter(new FileWriter("D:\\SecondElement_SourceCode\\1.txt"));
        //爬取网站源代码分析jpg写入InSecondElement
        URL u=new URL(b);
        InputStream i = u.openStream();
        System.out.println(i);
        String[] inJpg=new String[10];
        //1.将源代码存入数组
        byte[] f = new byte[1024*10];
        for (int j = 0;i.read(f)!=-1; j++) {
            inJpg[j]=new String(f,0,f.length);
        }
        out.close();
        i.close();
        return inJpg;

//<img src="/uploads/allimg/210317/001935-16159115757f04.jpg" alt="猫羽雫 蓝色眼睛女子 尾巴 女孩子 猫耳 猫 可爱二次元动漫4k壁纸">

      /*  //分析源代码数组，截取jpg图片参数
        outJpg = (Arrays.toString(inJpg)).split("<img src=");

        String[] outJpg2=new String[outJpg.length/2];
        for (int j = 1,k=0; j < outJpg.length; j+=2,k++) {
            outJpg2[k]=outJpg[j];
        }
        String[] outJpg3;
        outJpg3 = (Arrays.toString(outJpg2)).split(" alt=");
        for (int j = 0,k=0; j < outJpg2.length; j+=2,k++) {
            outJpg3[k]=outJpg2[j];
        }

        System.out.println(Arrays.toString(outJpg3));
*/
        //关闭流

    }
}
